#ifndef SMART_THREAD_H
#define SMART_THREAD_H

#include <string>
#include <thread>
#include <condition_variable>
#include <mutex>
#include <vector>
#include <functional>

/**
 * @brief The SmartThread class
 */
class SmartThread{
public:
    SmartThread();
    static SmartThread *instance();
    ~SmartThread();
    //设置线程执行函数
    void setFunc(const std::function<int()> func);
    //阻塞
    void block();
    //唤醒
    void notify();
    //设置子线程while循环间隔时间（毫秒）
    void setIntervalMs(const int ms){_intervalMs = ms;}
private:
    static void majorFunc();
private:
    static int _intervalMs;
    static bool _runFlag,_blockFlag;
    static std::condition_variable _condvab;
    static std::mutex _mtx;
    std::thread _thd;
    //    static std::function<int(const std::vector<std::string>&) > _func;
    static std::function<int()> _func;
};


#endif
